﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using RpgXna.Model.Entities;

namespace RpgXna.Model.Quest
{
    public enum QuestsStates
    {
        NotStarted,
        InProgress,
        Finished
    }

    class Quest
    {
        public Quest(string name, string description, IEnumerable<QuestObjective> obj)
        {
            Objectives = new List<QuestObjective>();
            Name = name;
            Description = description;
            Objectives.AddRange(obj);
        }

        public string Name { get; private set; }
        public string Description { get; private set; }

        public List<QuestObjective> Objectives { get; set; }

        public bool IsCompleted { get { return Objectives.All(o => o.Completed()); } }
    }

    abstract class QuestObjective
    {
        public string Name { get; set; }


        public bool Completed()
        {
            return InternalCompleted();
        }

        protected abstract bool InternalCompleted();
    }

    class ItemToLocationObjective : QuestObjective
    {
        private readonly PickableObject _item;
        private readonly Rectangle _tagerLocation;

        public ItemToLocationObjective(PickableObject o, Rectangle tagerLocation)
        {
            _item = o;
            _tagerLocation = tagerLocation;
        }

        protected override bool InternalCompleted()
        {
            return _item.Box.Intersects(_tagerLocation);
        }
    }




    class QuestBuilder
    {
        private List<Quest> _questList;

        public QuestBuilder()
        {
            _questList = new List<Quest>();

            BuildQuests();
        }

         void BuildQuests()
        {
            //var q1 = new Quest("Du respect pour les ainés.",
            //                     "Grand mère a besoin d'un solide gaillard pour lui apporter le tas bois a côté de sa cloture derrière sa maison",
            //                     new QuestObjective[]
            //                         {
            //                             new ItemToLocationObjective(EnvironmentRepository.GetItem<PickableObject>(2), new Rectangle(12010, 80, 100, 100))
            //                         });
            //_questList.Add(q1);
        }
    }
}
